<template>
  <div class="app-container">
    <!-- 上部分表单 -->
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      label-width="80px"
      label-position="top"
    >
      <div class="button-from">
        <el-form-item label="订单号" prop="orderNo">
          <el-input
            v-model="queryParams.orderNo"
            placeholder="请输入订单号"
            clearable
            @keyup.enter.native="handleQuery"
            style="width: 350px"
            size="small"
          />
        </el-form-item>
        <el-form-item label="客户姓名" prop="likeConsumer">
          <el-input
            v-model="queryParams.likeConsumer"
            placeholder="请输入客户姓名"
            clearable
            @keyup.enter.native="handleQuery"
            style="width: 350px"
            size="small"
          />
        </el-form-item>
        <el-form-item label="客户手机号" prop="customerPhone">
          <el-input
            v-model="queryParams.customerPhone"
            placeholder="请输入客户姓名"
            clearable
            @keyup.enter.native="handleQuery"
            style="width: 350px"
            size="small"
          />
        </el-form-item>
        <el-form-item label="油品名称" prop="oilName">
          <el-select
            v-model="queryParams.oilName"
            placeholder="油品名称"
            clearable
            style="width: 350px"
            size="small"
          >
            <el-option :value="undefined" selected>全部</el-option>
            <el-option
              :value="ele.oilId"
              v-for="ele in oilList"
              :key="ele.oilId"
              :label="ele.oilName + '-' + ele.oilClass + '-' + ele.oilType"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="支付方式" prop="payType">
          <el-select
            v-model="queryParams.payType"
            placeholder="支付方式"
            clearable
            style="width: 350px"
            size="small"
          >
            <el-option :value="undefined" selected>全部</el-option>
            <el-option value="wx" label="微信支付"></el-option>
            <el-option value="zfb" label="支付宝支付"></el-option>
            <el-option value="dzk" label="电子卡支付"></el-option>
            <el-option value="xj" label="现金支付"></el-option>
            <el-option value="yhk" label="银行卡支付"></el-option>
          </el-select>
        </el-form-item>
        <!--
        <el-form-item label="加油员" prop="oilPersonnel">
          <el-input
            v-model="queryParams.oilPersonnel"
            placeholder="请输入加油员"
            clearable
            style="width: 350px"
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>-->

        <el-form-item label="创建时间" prop="createdDate">
          <el-date-picker
            size="small"
            style="width: 350px"
            v-model="dateRangeCreatedDate"
            value-format="yyyy-MM-dd HH:mm:ss"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
          <div class="button-style1">
            <el-button
              type="primary"
              icon="el-icon-search"
              @click="handleQuery"
              size="small"
              >搜索</el-button
            >
          </div>
        </el-form-item>
        <!-- <el-form-item label="" prop="oilGun">
          <el-input
            v-model="queryParams.oilGun"
            style="width: 250px"
            size="small"
            placeholder="请输入油枪"
            clearable
            @keyup.enter.native="handleQuery"
          />
        
        </el-form-item>-->
      </div>
    </el-form>

    <el-form
      :model="orderSum"
      ref="orderSum"
      :inline="true"
      label-width="128px"
    >
      <!-- <el-form-item label="会员名" prop="customerName">
        <el-input
          v-model="queryParams.customerName"
          placeholder="请输入客户名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="实收总计" prop="amt">
        <div style="font-size: 1.5vw">{{ orderSum.amt }}元</div>
      </el-form-item>
      <el-form-item label="应收总计" prop="receivableAmt">
        <div style="font-size: 1.5vw">{{ orderSum.receivableAmt }}元</div>
      </el-form-item>
      <el-form-item label="升数总计" prop="orderLiters">
        <div style="font-size: 1.5vw">{{ orderSum.orderLiters }}元</div>
      </el-form-item>
      <el-form-item label="订单数" prop="countNum">
        <div style="font-size: 1.5vw">{{ orderSum.countNum }}元</div>
      </el-form-item>
    </el-form>
    <!-- 表格 -->
    <div class="card-table">
      <el-button icon="el-icon-message" size="small" type="success"
        >新增</el-button
      >
      <el-button icon="el-icon-message" size="small" @click="handleExport"
        >导出</el-button
      >
      <el-button icon="el-icon-message" size="small">打印</el-button>
      <el-table border style="width: 100%" :data="orderList">
        <af-table-column
          label="油站名"
          fixed
          align="left"
          prop="stationName"
          v-if="jiBie == 0 || jiBie == 1"
        />
        <af-table-column
          v-if="false"
          label="订单id"
          align="left"
          prop="orderId"
        />
        <af-table-column label="订单号" align="left" prop="orderNo" />
        <af-table-column label="油品名称" align="left" prop="oilName" />
        <af-table-column label="油品价格" align="left" prop="oilPirce" />
        <af-table-column
          label="加油数量(L/kg)"
          align="left"
          prop="orderLiters"
        />
        <af-table-column label="应付金额" align="left" prop="receivableAmt" />
        <af-table-column label="实付金额" align="left" prop="amt" />
        <af-table-column label="优惠金额" align="left" prop="discountAmt" />
        <af-table-column label="客户姓名" align="left" prop="consumer" />
        <af-table-column label="客户手机号" align="left" prop="customerPhone" />
        <af-table-column label="加油员" align="left" prop="oilPersonnel" />
        <af-table-column label="加油枪号" align="left" prop="oilGun" />
        <af-table-column
          label="支付类型"
          align="left"
          prop="payType"
          width="150px"
          :formatter="payTypeFotmat"
        />
        <af-table-column
          label="油站名称"
          align="left"
          v-if="false"
          prop="stationName"
        />
        <af-table-column
          v-if="false"
          label="用户id(消费者)"
          align="left"
          prop="consumerId"
        />
        <af-table-column
          v-if="false"
          label="油站id"
          align="left"
          prop="stationId"
        />
        <af-table-column
          label="状态"
          width="130px"
          align="left"
          prop="status"
          :formatter="statusFotmat"
        />
        <af-table-column label="支付时间" align="left" prop="payDate">
          <template slot-scope="scope">
            <span>{{
              parseTime(scope.row.payDate, "{y}-{m}-{d} {h}:{i}:{s}")
            }}</span>
          </template>
        </af-table-column>
        <af-table-column label="创建时间" align="left" prop="createdDate">
          <template slot-scope="scope">
            <span>{{
              parseTime(scope.row.createdDate, "{y}-{m}-{d} {h}:{i}:{s}")
            }}</span>
          </template>
        </af-table-column>
        <af-table-column
          label="操作"
          align="left"
          class-name="small-padding fixed-width"
          width="120px"
          v-if="reprint"
          fixed="right"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-plus"
              @click="printOrderInfo(scope.row)"
              >补打小票</el-button
            >
          </template>
        </af-table-column>
      </el-table>
    </div>
    <!-- 分页 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>
<script>
import {
  listOrder,
  exportOrder,
  printOrderInfo,
  selectSumPayOrder,
} from "@/api/station/order";
import { listPrice, getPrice } from "@/api/station/price";
import { listManage } from "@/api/station/manage";
import { getStationList } from "@/api/dept";
import { getOilListByLogin } from "@/api/dept";

export default {
  name: "Order_Oil",
  data() {
    return {
      //创建订单时间间隔
      dateRangeCreatedDate: [],
      // 总条数
      total: 0,
      // 订单支付表格数据
      orderList: [],
      oilNameOptions: [],
      // 字典
      payTypeOptions: [],
      // 下拉油站
      stationOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        levelId: this.levelId,
        pageNum: 1,
        pageSize: 10,
        oilGun: null,
        oilName: null,
        stationId: null,
        orderType: null,
        //orderType:1,
        oilPersonnel: null,
        createdDate: null,
        likeConsumer: null,
        orderNo: null,
        customerPhone: null,
      },
      orderSum: {
        amt: null,
        receivableAmt: null,
        orderLiters: null,
        countNum: null,
      },
      // 表单校验
      rules: {},
      reprint: false,
      oilList: [],
    };
  },
  created() {
    this.getList();
    this.getOilList();
    // listManage({
    //   pageNum: 1,
    //   pageSize: 1,
    // }).then((response) => {
    //   const equipmentList = response.rows;
    //   if (!!equipmentList) {
    //     if ((equipmentList[0] || {}).deviceType == "1") {
    //       this.reprint = true;
    //     }
    //   }
    // });
    //字典
    // this.getDicts("pay_type").then((response) => {
    //   this.payTypeOptions = response.data;
    // });
    // this.getDicts("oil_name").then((response) => {
    //   this.oilNameOptions = response.data;
    // });
  },
  methods: {
    getOilList() {
      getOilListByLogin()
        .then((res) => {
          if (res.code == 200) {
            this.oilList = res.rows;
            console.log(this.oilList);
          } else {
            throw new Error("");
          }
        })
        .catch(() => {
          this.msgError("拉取油品列表失败，请刷新网页~");
        });
    },
    payTypeFotmat(row, column) {
      if (row.payType === "wx") {
        return "微信支付";
      } else if (row.payType === "zfb") {
        return "支付宝";
      } else if (row.payType === "xj") {
        return "现金支付";
      } else if (row.payType === "dzk") {
        return "电子卡支付";
      } else if (row.payType === "POS") {
        return "POS机支付";
      } else if (row.payType === "yzf") {
        return "预支付";
      } else if (row.payType === "kbzf") {
        return "卡包支付";
      }
    },
    statusFotmat(row, column) {
      if (row.status === "0") {
        return "未支付";
      } else if (row.status === "1") {
        return "已支付";
      } else if (row.status === "2") {
        return "线下退款";
      } else if (row.status === "3") {
        return "线上退款";
      }
    },
    /** 查询订单支付列表 */
    getList() {
      this.queryParams.levelId = this.levelId;
      listOrder(
        this.addDateRange(this.queryParams, this.dateRangeCreatedDate)
      ).then((response) => {
        this.orderList = response.rows;
        this.total = response.total;
      });
      selectSumPayOrder(
        this.addDateRange(this.queryParams, this.dateRangeCreatedDate)
      ).then((response) => {
        this.orderSum = response.data;
      });
    },
    //   selectSumPayOrder() {
    //   this.queryParams.levelId = this.levelId;

    // },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRangeCreatedDate = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    //打印订单小票
    printOrderInfo(row) {
      printOrderInfo({ orderId: row.orderId }).then((response) => {
        this.msgSuccess("小票打印成功");
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有订单支付数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return exportOrder(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
        });
    },
  },
};
</script>
<style lang="scss" scoped>
.app-container {
  margin-top: -15px;
}
.button-from {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  .button-style1 {
    display: inline-block;
    width: 80px;
    .el-button {
      margin: 0 0 0 15px;
    }
  }
}
::v-deep .card-table {
  padding: 10px;
  margin-top: 20px;
  background-color: #f8f8f8;
  .el-button {
    margin: 0 5px 0 0;
  }
}
// 表格样式
::v-deep .el-form-item {
  margin-bottom: 0;
  .el-form-item__label {
    padding: 0;
    margin: 0;
    height: 29px;
    font-weight: 400;
    font-size: 12px;
  }
  .el-button--cyan {
    margin-left: 20px;
  }
}
::v-deep .el-table {
  border: 1px #f8f8f8 solid;
  border-bottom: 1px #dfe6ec solid;
}
::v-deep .is-center {
  border: 1px transparent solid;
  border-bottom: 1px #f8f8f8 solid;
}
</style>
